package school;

import java.util.*;

/**
 * @author: jack
 * @date: 2018/10/27 13:2420
 * @version: 0.1
 * @description: <文件的作用>
 * @modified: <修改说明>
 * Student继承Comparable接口原因：Collections工具类中的sort方法，有两种：comparable()默认的比较规则和comparator()临时的比较规则
 * implements Comparable测试重载默认的比较规则，继承接口需要实现Comparable的compareTo方法
 **/
public class Student implements Comparable<Student> {
    private String name;
    private String id;
    //定义set集泛型
    private Set<Course> courses=new HashSet<Course>();

    public String getId(){
        return id;
    }
    public void setId(String id){
        this.id=id;
    }
    public String getame(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public Set<Course> getCourses(){return courses;}
    public void setCourses(Course course){
        courses.add(course);
    }


    public Student(String id,String name){
        this.id=id;
        this.name=name;
//        this.courses=new HashSet<Course>();
    }
    @Override
    //重写equals方法，实现输入课程名称，相同即返回true,
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Student)) {
            return false;
        }
        Student student = (Student) obj;
        if (this.getame() == null) {
            if (student.getame() == null) {
                return true;
            } else {
                return false;
            }
        } else {
            if (this.getame().equals(student.getame())) {
                return true;
            } else {
                return false;
            }
        }
    }

    //重写hashCode方法，实现课程名称相同，即返回true
    @Override
    public int hashCode() {
        final int prime=31;
        int result=1;
        result=prime*result+((name==null)? 0:name.hashCode());
        return result;
    }

    @Override
    public int compareTo(Student o) {
        //student的id进行比较
        return this.id.compareTo(o.id);
    }
}
